package com.dgty.dg_common.util

import android.content.Context
import com.dgty.dg_common.widget.DatePickerPopup
import com.lxj.xpopup.XPopup
import com.lxj.xpopupext.listener.TimePickerListener
import java.util.Calendar

/**
 * Title: DateUtil.kt
 * Description:日期选择控件
 * Created DateTime: 2023-03-22
 * Created by xxl.
 */
object DateUtil {

    /**
     * 日期选择弹框
     */
    fun showDateDialog(context: Context, defaultDate: Calendar, listener: TimePickerListener) {
        val date: Calendar = Calendar.getInstance()
        date.set(2000, 1, 1)
        val date2: Calendar = Calendar.getInstance()
        date2.set(2022, 12, 31)
        val popup = DatePickerPopup(context)
            .setDefaultDate(defaultDate)  //设置默认选中日期
            //.setYearRange(1990, 1999) //设置年份范围
            .setDateRange(date, date2) //设置日期范围
            .setItemsVisibleCount(3)
            .setLineSpace(3.3f)
            .setShowLabel(false)
            .setTimePickerListener(listener)

        XPopup.Builder(context)
            .asCustom(popup)
            .show()
    }


}